home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!sun2!ua302aa
- From: ua302aa@sun2.lrz-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: qsort help
- Date: 3 Jan 1996 11:57:16 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4cdqus$j5i@sparcserver.lrz-muenchen.de>
- References: <4ccio7$7c0@charm.magnus.acs.ohio-state.edu> <4cdomq$jgt@dub-news-svc-5.compuserve.com>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- stuart.hayes@baesema.co.uk writes:
-
- >xiaoyi@bmecg.bme.ohio-state.edu (Xiaoyi Wu) wrote:
-
- >>Hi, I am having some problems with the qsort routine.
-
-
- >>int (*compar)(int *a, int *b)
- >Function declaration should be:
- >int compar(int *a, int *b)
- >Should also declare function in header file or top of source for
- >completeness
-
- What kind of "completeness" can be reached by declaring a function
- in a header file or "top of source". A functions definition provides
- enough information if it appears before the point of use.
-
- >>{
- >> if (*a < *b) return -1;
- >> else if (*a == *b) return 0;
- >> else return 1;
- >>}
-
-
- >Alternatively to declaring function in header file could just declare
- >in the function below:
-
- >>int return_moved_contour(int ix, int iy)
- >>{
- >int (*compar)(int *a, int *b);
-
- This declares a pointer to a function
-
- [some code that does not set the variable "compar" edited]
-
- >> qsort(y_coord, count, sizeof(int), compar);
-
- This uses an uninitialized pointer to a function. You could get another
- diagnostic message for this from a good compiler. If the compiler does
- _not_ reject this code, the results can be very interesting.
-
- >This is a first preliminary stab at this, haven't tried it.
- >Hope of some help.
-
- I'm afraid that the chances of this article to help anyone are pretty poor.
- But nothing is in vain; it can still serve as a bad example ;-).
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-